/*
 *  Copyright (C) 2010 Glauco
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.swing.transaction.panel;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.balisunrise.builder.BuilderException;
import org.balisunrise.swing.builder.LayoutBuilder;
import org.balisunrise.swing.components.focusManagers.JPanelFocusManager;

/**
 *
 * @author Glauco
 */
public class EditorPanel extends JPanel{

    JPanel messagePanel;
    JPanel entityPanel;
    JPanel actionPanel;

    LayoutBuilder layoutBuilder;

    private List<JComponent> list;

    private JPanelFocusManager focusManager;

    public EditorPanel(JPanel messagePanel, JPanel entityPanel,
            JPanel actionPanel, LayoutBuilder layoutBuilder) {

        super();

        this.messagePanel = messagePanel;
        this.entityPanel = entityPanel;
        this.actionPanel = actionPanel;

        this.layoutBuilder = layoutBuilder;

        list = new ArrayList<JComponent>();

        setMinimumSize(new Dimension(10, 315));

        createLayout();

        focusManager = new JPanelFocusManager(this);
    }

    public JPanel getActionPanel() {
        return actionPanel;
    }

    public void setActionPanel(JPanel actionPanel) {
        this.actionPanel = actionPanel;
        createLayout();
    }

    public JPanel getEntityPanel() {
        return entityPanel;
    }

    public void setEntityPanel(JPanel entityPanel) {
        this.entityPanel = entityPanel;
        createLayout();
    }

    public LayoutBuilder getLayoutBuilder() {
        return layoutBuilder;
    }

    public void setLayoutBuilder(LayoutBuilder layoutBuilder) {
        this.layoutBuilder = layoutBuilder;
        createLayout();
    }

    public JPanel getMessagePanel() {
        return messagePanel;
    }

    public void setMessagePanel(JPanel messagePanel) {
        this.messagePanel = messagePanel;
        createLayout();
    }

    public JPanelFocusManager getFocusManager() {
        return focusManager;
    }

    public void createLayout(){

        list.clear();

        list.add(messagePanel);
        list.add(entityPanel);
        list.add(actionPanel);

        try{
            layoutBuilder.create(this, list);
        }catch(BuilderException be){
            System.out.println(
                    "Erro em EditorPanel ao criar layout.\n"+
                    be.getMessage());
        }
    }
}
